<?php
    $x = new Zend_Auth_Storage_Session('User_Auth');
    $y = $x->read();

    //$_controllerName = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
    //$_actionName = Zend_Controller_Front::getInstance()->getRequest()->getActionName();

    
    if (empty($y))
    {
        ?>
        <div class="fr ht-right">
            <ul class="rnav">
                <li><a id="login-button" class="rbox li" href="#plog">Log in</a></li>
                <li><a id="caccount-button" class="current rbox ca" href="#reg-form">Create Account</a></li>
                <li><a class="rbox ab" href="<?php echo $this->baseUrl("static/about_us"); ?>">About us</a></li>
            </ul>
        </div>
        <?php
        echo $this->partial("extras/login-form-popup.phtml");
        echo $this->partial("extras/register-form-popup.phtml");
    }
    else
    {
        ?>
        <style>
            .h-top{
                padding-bottom: 0 !important;
            }
        </style>
        <div class="fr ht-right">
            <div class="htr-signout">
                <a href="<?php echo $this->baseUrl("index/logout"); ?>" class="tlink fr">Sign Out</a>
            </div>
            <ul class="rnav2">
                <li>
                    <a href="<?php echo $this->baseUrl("profile"); ?>">
                        <span class="name">Profile</span>
                        <span class="icon"><img rel="<?php echo IMAGES_PATH; ?>/home-icon-a.png" src="<?php echo IMAGES_PATH; ?>/home-icon.png" alt="profile" /></span>
                    </a> 
                </li>
                <li class="dropdown2 event-updates">
                    <span class="name"><a href="#">Event Updates</a></span>
                    <span class="icon" data-type="notification" data-count="<?php echo (count($this->getHelper('Message')->getEventNotification()) > 0) ? true : false; ?>" onclick="removeCount(this);">
                        <?php
                            
                        if (count($this->getHelper('Message')->getNotificationCounts()) > 0)
                        {
                            ?>    
                            <span class="msg-count"><?php echo count($this->getHelper('Message')->getNotificationCounts()); ?></span>
                            <?php
                        }
                        
                        
                        ?>    
                        <img rel="<?php echo IMAGES_PATH; ?>/update-icon-a.png" src="<?php echo IMAGES_PATH; ?>/update-icon.png" alt="home" />
                    </span>
                    <div class="rbox list-events shadow bradius3">
                        <div class="a-top"></div>
                        <?php
                        $notificationArr = $this->getHelper('Message')->getEventNotification();
                        //pr($notificationArr);
                        $flag_arr = array();
                        $flag_arr['event_id'] = array();
                        if (!empty($notificationArr))
//                            prd ($notificationArr);
                            foreach ($notificationArr as $nKey => $nValue)
                            {
                                ?>
                                <div class="item">
                                    <img class="fl thumb" src="<?php echo is_file(ROOT_PATH . "/" . MEMBER_IMAGE_PATH . "/" . $nValue['user_id'] . ".jpg") ? $this->baseUrl(MEMBER_IMAGE_PATH . "/" . $nValue['user_id'] . ".jpg") : $this->baseUrl(MEMBER_NO_IMAGE_FILE); ?>" alt="thumb" width="26" height="26"/>
                                    <div class="fl content link-to-event"  data-event-id ="<?php echo getEncryptedString($nValue['notification_event_id']); ?>" data-is-clickable="<?php echo $nValue['status_code']==1&&!in_array($nValue['notification_event_id'], $flag_arr['event_id'])? false:true; ?>">

                                        <?php
                                            
                                        switch ($nValue['status_code'])
                                        {

                                            case 1:
                                                //pr($flag_arr);
                                                if (!in_array($nValue['notification_event_id'], $flag_arr['event_id'])):
                                                    ?>
                                                    <p><?php echo $nValue['user_first_name'] . " " . $nValue['user_last_name']; ?> has requested to join event <i>"<?php echo stripslashes($nValue['event_title']); ?>"</i> </p>
                                                    <p><a class="rbox fr accept-link"  onclick ="window.location.href = this.href" href="<?php echo $this->baseUrl("ajax/eventrequest/respond/accept/ejId/" . $nValue['ej_id'] . "/eventId/".$nValue['event_id']."?redirect_uri=" . curPageURL()); ?>" >Accept</a><span class='fr'>&nbsp;&nbsp;</span>
                                                        <a class="rbox fr reject-link" onclick ="window.location.href = this.href" href="<?php echo $this->baseUrl("ajax/eventrequest/respond/reject/ejId/" . $nValue['ej_id'] . "?redirect_uri=" . curPageURL()); ?>" >Reject</a>
                                                    </p> 
                                                    <?php
                                                    
                                                else:
                                                    ?>
                                                    <p><?php echo $nValue['user_first_name'] . " " . $nValue['user_last_name']; ?> has requested to join event <i>"<?php echo stripslashes($nValue['event_title']); ?>"</i> </p>
                                                <?php
                                                endif;

                                                break;
                                            case 2:
                                                //echo $nValue['notificaton_event_joiner'];
                                                if (!empty($nValue['notification_event_joiner']))
                                                {
                                                    ?>
                                                    <p><?php echo $nValue['user_first_name'] . " " . $nValue['user_last_name']; ?> has left event <i>"<?php echo stripslashes($nValue['event_title']); ?>"</i> </p>
                                                    <?php
                                                }
                                                else
                                                {
                                                    ?>
                                                    <p>You successfully left event <i>"<?php echo stripslashes($nValue['event_title']) ?>"<i></p>
                                                                <?php
                                                            }
                                                            break;
                                                        case 3: echo "<p>Your request for joining event <i>\"" . $nValue["event_title"] . "\"</i> has been approved</p>";
                                                            break;

                                                        case 4: echo "<p>Your request for joining event <i>\"" . $nValue["event_title"] . "\"</i> has been rejected</p>";
                                                            break;

                                                        case 5: if (!empty($nValue['notification_event_joiner']))
                                                                echo "<p><span class='blu'>" . $nValue["user_first_name"] . " " . $nValue["user_last_name"] . "</span>";
                                                            else
                                                                echo "<p> you";
                                                            echo "</i> successfully joined  event <i>" . stripslashes($nValue['event_title']) . "</i> </p>";
                                                            break;
                                                        case 6: echo "<p>" . $nValue["user_first_name"] . " " . $nValue["user_last_name"] . "</i> was successfully rejected joining event <i>" . stripslashes($nValue['event_title']) . "</i> </p>";
                                                            break;
                                                        case 7: echo "<p> You were removed from event <i>" . stripslashes($nValue['event_title']) . "</i></p>";
                                                            break;
                                                        case 8: echo "<p>" . $nValue["user_first_name"] . " " . $nValue["user_last_name"] . "</i> was successfully removed from event <i>" . stripslashes($nValue['event_title']) . "</i></p>";
                                                            break;
                                                        case 9: echo "<p>" . $nValue["event_title"] . " has been modified.</p>";
                                                            break;
                                                        case 10: echo "<p>" . $nValue["notification_message"] . "</p>";
                                                            break;
                                                    
                                                        case 11: echo "<p>".str_replace("Host",$nValue["user_first_name"]." ".$nValue["user_last_name"],$nValue["status_message"])."</p>"; break;
                                                    }
                                                    $flag_arr['event_id'][] = $nValue['notification_event_id'];
                                                    ?>
                                                    <!--<p class="time"><?php echo getTimeAgo(strtotime($nValue['ej_timestamp'])); ?></p>-->
                                                    <p class="time"><?php echo getTimeAgo(strtotime($nValue['notification_timestamp'])); ?></p>
                                                    </div>
                                                    <div class="cf"></div>
                                                    </div>
                                                    <?php
                                                }
                                            ?>
                                            <div class="see-more">
                                                See updates in <a href="<?php echo $this->baseUrl("event/eventupdates"); ?>" class="tlink">Inbox</a>
                                            </div>
                                            </div>
                                            </li>
                                            <li class="dropdown2 im">
                                                <span class="name"><a href="#">IM</a></span>
                                                <span class="icon" data-type="message" data-count="<?php echo (count($this->getHelper('Message')->getMessageCounts()) > 0) ? true : false; ?>" onclick="removeCount(this);">
                                                    <img rel="<?php echo IMAGES_PATH; ?>/im-icon-a.png" src="<?php echo IMAGES_PATH; ?>/im-icon.png" alt="home" />
                                                    <?php
                                                    if (count($this->getHelper('Message')->getMessageCounts()) > 0)
                                                    {
                                                        ?>    
                                                        <span class="msg-count"><?php echo count($this->getHelper('Message')->getMessageCounts()); ?></span>
                                                        <?php
                                                    }
                                                    ?>    
                                                </span>
                                                <div class="rbox list-events shadow bradius3">
                                                    <div class="a-top"></div>
                                                    <?php
                                                    $msgArr = $this->getHelper('Message')->getNotifications($y->user_id);
                                                    if (!empty($msgArr))
                                                    {
//                                                        prd($msgArr);
                                                        foreach ($msgArr as $mKey => $mValue)
                                                        {
                                                            ?>    
                                                            <div class="item">
                                                                <img class="fl thumb" src="<?php echo is_file(ROOT_PATH . "/" . MEMBER_IMAGE_PATH . "/" . $mValue['user_id'] . ".jpg") ? $this->baseUrl(MEMBER_IMAGE_PATH . "/" . $mValue['user_id'] . ".jpg") : $this->baseUrl(MEMBER_NO_IMAGE_FILE); ?>" alt="thumb" width="26" height="26"/>
                                                                <div class="fl content">

                                                                    <?php
                                                                    if ($mValue['is_request'] == 'true')
                                                                    {
                                                                        ?>   
                                                                        <p><a href="#" class="ename"><?php echo $mValue['content']; ?></a></p>
                                                                        <p class="time"><?php echo getTimeAgo(strtotime($mValue['request_timestamp'])); ?></p>
                                                                        <p><a class="rbox fr accept-request accept-link" href="javascript:;" data-url ="<?php echo $this->baseUrl("ajax/friendrequest/respond/accept/rId/" . $mValue['_request_id']); ?>">Accept</a><span class='fr'>&nbsp;&nbsp;</span>
                                                                            <a class="rbox fr accept-request reject-link" href="javascript:;" data-url="<?php echo $this->baseUrl("ajax/friendrequest/respond/reject/rId/" . $mValue['_request_id']); ?>">Reject</a>
                                                                        </p>
                                                                        <?php
                                                                    }
                                                                    else
                                                                    {
                                                                        ?>    
                                                                        <p><a href="#" class="ename"><strong><?php echo $mValue['full_name']; ?></strong> - <?php echo substr($mValue['content'], 0, 30); ?>...</a></p>   
                                                                        <p class="time"><?php echo getTimeAgo(strtotime($mValue['request_timestamp'])); ?></p>
                                                                        <?php
                                                                    }
                                                                    ?>     

                                                                </div>
                                                                <div class="cf"></div>
                                                            </div>

                                                            <?php
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ?>
                                                        <div class="item"><p>No updates yet</p></div>
                                                        <?php
                                                    }
                                                    ?>    
                                                    <div class="see-more">
                                                        See updates in <a href="<?php echo $this->baseUrl("message"); ?>" class="tlink">Inbox</a>
                                                    </div>
                                                </div>
                                            </li>
                                            <li class="actived">
                                                <a href="<?php echo $this->baseUrl("static/about_us"); ?>">
                                                    <span class="name">About us</span>
                                                    <span class="icon"><img rel="<?php echo IMAGES_PATH; ?>/about-us-icon.png" src="<?php echo IMAGES_PATH; ?>/about-us-icon-a.png" alt="About us" /></span>
                                                </a>
                                            </li>
                                            </ul>
                                            </div>
                                            <?php
                                        }
                                    ?>